/**
 * ===========================================================================
 * 版权所有 湖南免了么网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.mianle.me
 * ===========================================================================
 * 15:23 2018/7/13
 */
package com.mianle.userapi.service.cglib.demo1;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.NoOp;

/**
 * @Author: yiyuan
 * @Description:
 * @Date: Created in 15:23 2018/7/13
 */
public class TableDAOFactory {

    private static class SigHolder {
        private final static TableDAO tDao = new TableDAO();
    }

    public static TableDAO getInstance() {
        return SigHolder.tDao;
    }

    public static TableDAO getAuthInstance(AuthProxy authProxy){
        Enhancer en = new Enhancer();
        //设置要代理的类
        en.setSuperclass(TableDAO.class);
        //表示设置回调即MethodInterceptor的实现类表示设置回调即MethodInterceptor的实现类
        en.setCallback(authProxy);
        //生成代理实例
        return (TableDAO)en.create();
    }

    public static TableDAO getAuthInstanceByFilter(AuthProxy authProxy){
        Enhancer en = new Enhancer();
        en.setSuperclass(TableDAO.class);
        en.setCallbacks(new Callback[]{authProxy, NoOp.INSTANCE});
        en.setCallbackFilter(new AuthProxyFilter());
        return (TableDAO)en.create();
    }
}
